package com.ruoyi.emergency.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.firefighter.domain.FirefighterInfo;
import com.ruoyi.firefighter.service.IFirefighterInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.emergency.mapper.FirefighterEmergencyMapper;
import com.ruoyi.emergency.domain.FirefighterEmergency;
import com.ruoyi.emergency.service.IFirefighterEmergencyService;

/**
 * 重大应急救援任务Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class FirefighterEmergencyServiceImpl implements IFirefighterEmergencyService
{
    @Autowired
    private FirefighterEmergencyMapper firefighterEmergencyMapper;
    @Autowired
    private IFirefighterInfoService iFirefighterInfoService;
    /**
     * 查询重大应急救援任务
     *
     * @param id 重大应急救援任务主键
     * @return 重大应急救援任务
     */
    @Override
    public FirefighterEmergency selectFirefighterEmergencyById(Long id)
    {
        return firefighterEmergencyMapper.selectFirefighterEmergencyById(id);
    }

    /**
     * 查询重大应急救援任务列表
     *
     * @param firefighterEmergency 重大应急救援任务
     * @return 重大应急救援任务
     */
    @Override
    public List<FirefighterEmergency> selectFirefighterEmergencyList(FirefighterEmergency firefighterEmergency)
    {
        return firefighterEmergencyMapper.selectFirefighterEmergencyList(firefighterEmergency);
    }

    /**
     * 新增重大应急救援任务
     *
     * @param firefighterEmergency 重大应急救援任务
     * @return 结果
     */
    @Override
    public int insertFirefighterEmergency(FirefighterEmergency firefighterEmergency)
    {
        FirefighterInfo firefighterInfo1 = new FirefighterInfo();
        firefighterInfo1.setIdCardNumber(firefighterEmergency.getFirefighterIdCard());
        FirefighterInfo firefighterInfo= iFirefighterInfoService.selectFirefighterInfoBySfz(firefighterInfo1);
        if (firefighterInfo==null){
            return 0;
        }
        firefighterEmergency.setFirefighterId(firefighterInfo.getUserId());
        firefighterEmergency.setCreateTime(DateUtils.getNowDate());
        return firefighterEmergencyMapper.insertFirefighterEmergency(firefighterEmergency);
    }

    /**
     * 修改重大应急救援任务
     *
     * @param firefighterEmergency 重大应急救援任务
     * @return 结果
     */
    @Override
    public int updateFirefighterEmergency(FirefighterEmergency firefighterEmergency)
    {
        firefighterEmergency.setUpdateTime(DateUtils.getNowDate());
        return firefighterEmergencyMapper.updateFirefighterEmergency(firefighterEmergency);
    }

    /**
     * 批量删除重大应急救援任务
     *
     * @param ids 需要删除的重大应急救援任务主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterEmergencyByIds(Long[] ids)
    {
        return firefighterEmergencyMapper.deleteFirefighterEmergencyByIds(ids);
    }

    /**
     * 删除重大应急救援任务信息
     *
     * @param id 重大应急救援任务主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterEmergencyById(Long id)
    {
        return firefighterEmergencyMapper.deleteFirefighterEmergencyById(id);
    }

    @Override
    public List<FirefighterEmergency> selectFirefighterEmergencyByName(String emergency) {
        return firefighterEmergencyMapper.selectFirefighterEmergencyByName(emergency);
    }

    @Override
    public void deleteFirefighterEmergencyById1(Long userId) {
        firefighterEmergencyMapper.deleteFirefighterEmergencyByIduser(userId);
    }
}
